//
//  XSQADShowVC.m
//  BuDeJie
//
//  Created by Sem on 2018/6/27.
//  Copyright © 2018年 SEM. All rights reserved.
//
#define XSQCode2 @"phcqnauGuHYkFMRquANhmgN_IauBThfqmgKsUARhIWdGULPxnz3vndtkQW08nau_I1Y1P1Rhmhwz5Hb8nBuL5HDknWRhTA_qmvqVQhGGUhI_py4MQhF1TvChmgKY5H6hmyPW5RFRHzuET1dGULnhuAN85HchUy7s5HDhIywGujY3P1n3mWb1PvDLnvF-Pyf4mHR4nyRvmWPBmhwBPjcLPyfsPHT3uWm4FMPLpHYkFh7sTA-b5yRzPj6sPvRdFhPdTWYsFMKzuykEmyfqnauGuAu95Rnsnbfknbm1QHnkwW6VPjujnBdKfWD1QHnsnbRsnHwKfYwAwiu9mLfqHbD_H70hTv6qnHn1PauVmynqnjclnj0lnj0lnj0lnj0lnj0hThYqniuVujYkFhkC5HRvnB3dFh7spyfqnW0srj64nBu9TjYsFMub5HDhTZFEujdzTLK_mgPCFMP85Rnsnbfknbm1QHnkwW6VPjujnBdKfWD1QHnsnbRsnHwKfYwAwiuBnHfdnjD4rjnvPWYkFh7sTZu-TWY1QW68nBuWUHYdnHchIAYqPHDzFhqsmyPGIZbqniuYThuYTjd1uAVxnz3vnzu9IjYzFh6qP1RsFMws5y-fpAq8uHT_nBuYmycqnau1IjYkPjRsnHb3n1mvnHDkQWD4niuVmybqniu1uy3qwD-HQDFKHakHHNn_HR7fQ7uDQ7PcHzkHiR3_RYqNQD7jfzkPiRn_wdKHQDP5HikPfRb_fNc_NbwPQDdRHzkDiNchTvwW5HnvPj0zQWndnHRvnBsdPWb4ri3kPW0kPHmhmLnqPH6LP1ndm1-WPyDvnHKBrAw9nju9PHIhmH9WmH6zrjRhTv7_5iu85HDhTvd15HDhTLTqP1RsFh4ETjYYPW0sPzuVuyYqn1mYnjc8nWbvrjTdQjRvrHb4QWDvnjDdPBuk5yRzPj6sPvRdgvPsTBu_my4bTvP9TARqnam"
#import "XSQADShowVC.h"
#import "XSQMainTBController.h"
#import "XSQADHttpManager.h"
#import "XSQADModel.h"

@interface XSQADShowVC ()
@property (weak, nonatomic) IBOutlet UIView *showADView;
@property (weak, nonatomic) IBOutlet UIButton *showBtn;
@property (weak,nonatomic) NSTimer  *time;
@property (strong,nonatomic)XSQADModel *adModel;
@end

@implementation XSQADShowVC
- (IBAction)jumpAct:(UIButton *)sender {
    UIWindow *window =[UIApplication sharedApplication].keyWindow;
    XSQMainTBController *vc=[[XSQMainTBController alloc]init];
    //vc.view.backgroundColor =[UIColor redColor];
    window.rootViewController = vc;
    [window makeKeyWindow];
    [self.time invalidate];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _time =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeStar) userInfo:nil repeats:YES];
    
    [self.time fire];
    [self loadData];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(void)loadData{
    NSDictionary *dic=@{@"code2":XSQCode2};
    [XSQADHttpManager getAD:dic success:^(NSArray *adArr) {
        self.adModel =[adArr firstObject];
        [self loadADImageView];
    } failure:^(NSError *err) {
        
    }];
}
-(void)loadADImageView{
    CGFloat h =ScreenW/self.adModel.w*self.adModel.h;
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, h)];
    imageView.userInteractionEnabled=YES;
    [self.showADView addSubview:imageView];
    [imageView sd_setImageWithURL:[NSURL URLWithString:self.adModel.w_picurl]];
    UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tag)];
    [imageView addGestureRecognizer:tap];
}
-(void)tag{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.adModel.ori_curl]];
}
-(void)dealloc{
    NSLog(@"adDeallo");
}
-(void)timeStar{
    static int count =3;
    count--;
    
    if(count==-1){
        
        [self jumpAct:nil];
    }
    [_showBtn setTitle:[NSString stringWithFormat:@"跳过(%d)",count] forState:UIControlStateNormal];
}



@end
